package com.pkche.core.advanced.util;

import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

import org.apache.commons.lang.StringUtils;

public class SystemGlobals {
	
	private static CompositeConfiguration config ;
	
	/**
	 * 
	 * 文件内容读入内存
	 */
	public static void loadConfig(String configFile) throws ConfigurationException {
		
		CompositeConfiguration config = new CompositeConfiguration();
		config.addConfiguration(new PropertiesConfiguration(configFile));
		SystemGlobals.config = config;
		
	}
	
	/**
	 * 
	 * 读取配置文件值
	 */
	public static String getValue(String paramName) {
		
		String str = "";
		if(paramName.contains(" ")) {
			for(String s : paramName.split(" ")) {
				str += config.getString(s);
			}
			return str;
		}
		return config.getString(paramName);
		
	}
	
	/**
	 * 
	 * 读取配置文件值，如不存在则返回默认值
	 */
	public static String getValue(String paramName, String defaultValue) {
		
		String value = config.getString(paramName);
		if(StringUtils.isBlank(value)) {
			return defaultValue;
		}
		return value;
		
	}

}
